load("@rules_gazebo//gazebo:headers.bzl", "gz_export_header")

package(
    default_applicable_licenses = ["//:license"],
    features = [
        "layering_check",
        "parse_headers",
    ],
)

gz_export_header(
    name = "Export",
    out = "include/gz/transport/parameters/Export.hh",
    export_base = "GZ_TRANSPORT_PARAMETERS",
    lib_name = "gz-transport-parameters",
)

public_headers_no_gen = glob(["include/gz/transport/parameters/*.hh"])

private_headers = glob(["src/*.hh"])

sources = glob(
    ["src/*.cc"],
    exclude = [
        "src/*_TEST.cc",
    ],
)

public_headers = public_headers_no_gen + [
    "include/gz/transport/parameters/Export.hh",
]

cc_library(
    name = "parameters",
    srcs = sources + private_headers,
    hdrs = public_headers,
    features = [
        # Layering check fails for clang build due to no module exporting
        # `google/protobuf/any.h`. Unfortunately, the bazel target that exports
        # this header in protobuf is private.
        "-layering_check",
    ],
    includes = ["include"],
    visibility = ["//visibility:public"],
    deps = [
        "//:gz-transport",
        "@com_google_protobuf//:protobuf",
        "@gz-msgs//:gzmsgs_cc_proto",
        "@sqlite3",
    ],
)

test_sources = glob(
    include = ["src/*_TEST.cc"],
)

[cc_test(
    name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
    srcs = [src],
    copts = [
        "-Wno-private-header",  # Required for Utils_TEST
    ],
    deps = [
        ":parameters",
        "//test:utils",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
        "@gz-msgs//:gzmsgs_cc_proto",
    ],
) for src in test_sources]
